Subject: Re: Here's a neat idiom for y'all...
From: [email-masked] (Lawrence Kirby)
Date: Tue, 22 Mar 1994 20:16:35 +0000
Newsgroups: comp.lang.c++,comp.lang.c

In article <[email-masked]>
           [email-masked] "Fred McCall" writes:

>: ANd besides, any half-decent compiler will emit a warning on construct like
>: "if (a = b)", so the probelm is non-existent to begin with.
>
>I hate compilers that do this.  It's one of those messages I turn off
>(because this isn't a mistake that I, personally, make -- I make other
>mistakes, instead -- and because there are a lot of times when I *am*
>doing an assignment in the conditional clause and I don't want my real
>errors obscured by a bunch of noisy warnings).

It's common to add an extra set of parentheses to indicate that this is what
was really intended as in:

if ((a = b))

Compilers like gcc recognise this and suppress the warning. It also makes
things much clearer to somebody else maintaining the code. It's quite natural
for assignments in expressiojns to be parenthesised e.g.

if ((ch = getchar()) == EOF)

-----------------------------------------
Lawrence Kirby | [email-masked]
Wilts, England | [email-masked]
-----------------------------------------